package proc

import (
	"common"
	"encoding/json"
	"fmt"
	"utils"
)

// 处理消息
type SmsProc struct {

}

// SendGroupMessage send group message
func (this *SmsProc) SendGroupMessage(content string) {
	var smsMes common.SmsMes
	smsMes.Content = content
	smsMes.UserId = curUser.UserId

	data, err := json.Marshal(smsMes)
	if err != nil {
		fmt.Println("SendGroupMessage json.Marshal(smsMes) err", err)
		return
	}

	var mes common.Message
	mes.Type = common.SmsMessageType
	mes.Data = string(data)

	data, err = json.Marshal(mes)
	if err != nil {
		fmt.Println("SendGroupMessage json.Marshal(mes) err", err)
		return
	}

	// send message
	ut := &utils.Utils{
		Conn: curUser.Conn,
	}
	if err = ut.WriteMes(&mes); err != nil {
		fmt.Println("SendGroupMessage send message err", err)
		return
	}
}

func showMessage(mes *common.Message) {
	var smsMes common.SmsMes
	if err := json.Unmarshal([]byte(mes.Data), &smsMes); err != nil {
		fmt.Println("showMessage json.Unmarshal err", err)
		return
	}
	fmt.Printf("rev id=%v, info is %v\n\n", smsMes.UserId,smsMes.Content)
}
